<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <!-- 旋转数组：已知一个长度为 n 的数组，预先按照升序排列，经由 1 到 n 次 旋转 后，得到输入数组 -->
    <script>
      let rotate = function (nums, k) {
        if (k > 0) {
          let arr = []
          for (let i = 0; i < nums.length; i++) {
            arr[i] = nums[i]
          }
          for (let i = 0; i < nums.length; i++) {
            nums[(i + k) % arr.length] = arr[i]
          }
          return nums
        }
      }
      console.log(rotate([1, 2, 3, 4, 5], 3))
    </script>
  </body>
</html>
